<?

require(dirname(__FILE__).'/_base/BaseTaskProject.php');

class TaskProject extends BaseTaskProject{
    
    public $adminName='Проекты';
    public $pluralNames=array('Проект');
    
    public static function model($className=__CLASS__) {
        return parent::model($className);
    }
    
    public function rules() {
        return array(
            array('name, code', 'required'),
            array('id, time_create', 'numerical', 'integerOnly'=>true),
            array('time_create', 'default', 'setOnEmpty'=>true, 'value'=>time()),
            array('name, code', 'length', 'max'=>255),
            array('id, name, code, time_create', 'safe', 'on'=>'search'),
        );
    }
    
    public function relations() {
        return array(
            'users' => array(self::HAS_MANY, 'TaskProjectUser', 'project_id')
        );
    }
    
    public function findByCode($code, $with=false){
        $code = trim(substr(strip_tags($code), 0, 60));
        if(empty($code)) throw new CException(TaskModule::t('messages', 'Не указан код проекта.'));
        $model = self::model();
        if($with) $model = $model->with($with);
        return $model->findByAttributes(array('code'=>$code));
    }
    
    public function attributeLabels() {
        return array(
            'id' => TaskModule::t('fields', 'ID'),
            'name' => TaskModule::t('fields', 'Название'),
            'code' => TaskModule::t('fields', 'Код'),
            'time_create' => TaskModule::t('fields', 'Дата создания'),
        );
    }
    
    public function attributeWidgets(){
        return array(
            array('time_create','timestamp-show'),
        );
    }
    public function adminSearch(){
        return array(
            'columns'=>array(
                'id',
                'code',
                'name',
            ),
        );
    }
    
    public function adminUpdateFormIgnoreValues(){
        return array(
        );
    }
    
    public function GetHelpMessage($attr){
        $mes = array(
        );
        return $mes[$attr];
    }
    
}
